/*
 * @Author: yanzengyong 709402944@qq.com
 * @Date: 2025-07-21 17:16:55
 * @LastEditors: yanzengyong 709402944@qq.com
 * @LastEditTime: 2025-07-22 18:05:13
 * @FilePath: /cyj-boot-parent/cyj-boot-web/src/components/Common/largeFileUpload/src/api.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defHttp } from '/@/utils/http/axios';
import { objectToFormData } from './helper';
interface partUpload1 {
  fileName?: string;
  fileSize: number;
  fileType: string;
  busMsg?: string;
}
interface resPartUpload1 {
  objectKey: string;
  uploadId: string;
}
interface resPartUpload3 {
  fileKey: string;
  fileType: string;
  fileName: string;
  url: string;
  size: number;
  [key: string]: any;
}

interface sinleUploadParams {
  file: Blob;
  fileName: string;
  busMsg: string;
  dir: string;
}

// 开启分片上传获取文件key 和 上传 id
export const initPartUpload = (params: partUpload1): Promise<resPartUpload1> => defHttp.get({ url: '/api/usb/file/initiatePartUpload', params });

// 前端切片循环上传
export const uploadPartFile = (params: any, timeOut: number): Promise<any> =>
  defHttp.post({ url: '/api/usb/file/uploadPartFile', params, timeout: timeOut * 1000, headers: { 'Content-Type': 'multipart/form-data' } });
// 提交分片上传
export const completeParts = (params: resPartUpload1): Promise<resPartUpload3> => defHttp.get({ url: '/api/usb/file/completeParts', params });

// 删除分片文件
export const removePartFile = (params: resPartUpload1): Promise<any> => defHttp.get({ url: '/api/usb/file/clearParts', params });

// 单文件上传
export const singleUpload = (params: sinleUploadParams, timeOut: number): Promise<any> =>
  defHttp.post({
    url: '/api/usb/file/singleFileUpload',
    params: objectToFormData(params),
    timeout: timeOut * 1000,
    headers: { 'Content-Type': 'multipart/form-data' },
  });
